/**
 * 新增质量回访
 * @author 孙汉斌
 */
package com.zjht.gmcc.servlet.ass;

import java.io.PrintWriter;
import java.sql.PreparedStatement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zjht.gmcc.bean.BaseServlet;
import com.zjht.gmcc.bean.action.AssessUtil;
import com.zjht.gmcc.bean.util.MyJDBC;

public class AddReturnAss extends BaseServlet {

	private static final long serialVersionUID = 1L;

	protected boolean process(HttpServletRequest request, HttpServletResponse response, HttpSession session, PrintWriter out, MyJDBC myJDBC,
			String menu) throws Exception {

		String s_providerID = request.getParameter("providerid");// 供应商ID
		String s_filecode = request.getParameter("filecode");// 文件号
		String s_score = request.getParameter("score");// 考核结果
		String s_opinion = request.getParameter("opinion");// 处理意见(0-正常;1-异常)
		if (AssessUtil.ASS_RETURN_ABNORMAL.equals(s_opinion)) {// 异常
			s_opinion = request.getParameter("abnormal");// 异常类型(80-不推荐外省,81-暂停合作,82-重新认证)
		}
		String s_assessdate = request.getParameter("assessdate");// 考核时间
		String s_assessoper = request.getParameter("assessoper");// 经办人
		String s_memo = request.getParameter("memo");// 备注说明

		// 数据插入Assess表
		PreparedStatement ps = null;
		int flag = 0;
		StringBuilder sql = new StringBuilder();
		sql
				.append("INSERT INTO ASSESS(assessid,providerid,assessdate,score,memo,assessoper,opinion,filecode,assesstype)VALUES(SEQ_ASSESS_ID.NEXTVAL,?,?,?,?,?,?,?,'1')");
		ps = myJDBC.prepareStatement(sql);
		ps.setString(1, s_providerID);
		ps.setString(2, s_assessdate);
		ps.setString(3, s_score);
		ps.setString(4, s_memo);
		ps.setString(5, s_assessoper);
		ps.setString(6, s_opinion);
		ps.setString(7, s_filecode);
		flag = ps.executeUpdate();
		ps.close();
		ps = null;

		// 若处理意见为异常,则修改Provider表对应字段
		if (flag == 1 && !"0".equals(s_opinion)) {// 异常
			flag = 0;
			sql = new StringBuilder();
			sql.append("UPDATE Provider SET ");
			if (AssessUtil.ASS_RETURN_STOP_OUTSIDE.equals(s_opinion)) {//不推荐外省
				sql.append(" rangetype='0'");
			} else if (AssessUtil.ASS_RETURN_STOP_COOPER.equals(s_opinion)) {//停止合作
				sql.append(" orderstatus='2'");
			} else if (AssessUtil.ASS_RETURN_PERMIT_AGAIN.equals(s_opinion)) {//重新认证
				sql.append(" permitstatus='0'");
			}
			sql.append(" WHERE providerid=?");
			ps = myJDBC.prepareStatement(sql);
			ps.setString(1, s_providerID);
			flag = ps.executeUpdate();
		}

		String tip = "新增质量回访";
		if (flag == 1) {
			alert(out, tip + "成功", "/ass/ass.jsp");
		} else {
			errAlert(request, out, menu, tip + "失败");
		}
		return flag == 1;
	}

}
